home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
msqc25t1
/
keys.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-09-29
|
3KB
|
103 lines
/* keys.c: Captures and displays kepresses */
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <graph.h>
#include "textscrn.h"
#ifndef TRUE
#define FALSE 0
#define TRUE !FALSE
#endif
/* Local functions */
void setUpScreen (void);
int extended (void);
main()
{
char key;
int row = 1, col, repeating, c = 2;
setUpScreen (); /* create work screen */
/* Loop to process keypresses */
do {
col = c;
_settextposition (row, col); /* place cursor */
key = getch(); /* get next keypress */
if (key == 0) /* if null char */
repeating = extended (); /* handle extended code */
else
if (key == ' ')
_outtext ("Space");
else
if (key == 27)
_outtext ("ESC");
else
_outch (key); /* else show char */
if (++row > 17)
row = 1, c+= 16;
if (c > 78) repeating = 0; /* quit if screen full */
} while (repeating);
/* End of run */
_setbordwindow (1, 1, 25, 80, 0, LTGRAY, BLACK);
_displaycursor (_GCURSORON);
} /*---------------------------------------------------------------*/
void setUpScreen (void)
/* Build display */
{
/* Set up instruction box */
_displaycursor (_GCURSOROFF); /* turn off cursor */
_setbordwindow (1, 1, 5, 80, 2, WHITE, BLUE);
_settextposition (2, 32); /* print instructions */
_outtext ("Keyboard Sampler");
_settextposition (3, 16);
_outtext ("Press any key and the program reports what it is");
_settextposition (4, 32);
_outtext ("Quit with Alt-X");
/* Construct program workarea */
_setbordwindow (7, 2, 23, 79, 1, WHITE, BLACK);
} /*------------------------------------------------------------------*/
extended (void) /* process extended codes */
{
char ext;
int keepOn = TRUE; /* TRUE is default */
ext = getch(); /* get second byte */
switch (ext) {
case 45: keepOn = 0; break; /* Alt-X for quit */
case 59: _outtext ("F1"); break;
case 60: _outtext ("F2"); break;
case 61: _outtext ("F3"); break;
case 62: _outtext ("F4"); break;
case 63: _outtext ("F5"); break;
case 64: _outtext ("F6"); break;
case 65: _outtext ("F7"); break;
case 66: _outtext ("F8"); break;
case 67: _outtext ("F9"); break;
case 68: _outtext ("F10"); break;
case 71: _outtext ("Home"); break;
case 72: _outtext ("Cursor up"); break;
case 73: _outtext ("PgUp"); break;
case 75: _outtext ("Cursor left"); break;
case 77: _outtext ("Cursor right"); break;
case 79: _outtext ("End"); break;
case 80: _outtext ("Cursor down"); break;
case 81: _outtext ("PgDn"); break;
case 82: _outtext ("Ins"); break;
case 83: _outtext ("Del"); break;
default: _outtext ("Other ext key");
}
return keepOn;
}